//
//  CustomOverlayView.m
//  VinScanner
//
//  Created by Le Quang Vinh on 11/29/12.
//  Copyright (c) 2012 Le Quang Vinh. All rights reserved.
//

#import "CustomOverlayView.h"

@implementation CustomOverlayView

@synthesize delegate            = _delegate;
@synthesize pictureBtn          = _pictureBtn;
@synthesize cancelCaptureBtn    = _cancelCaptureBtn;
@synthesize nameCaptureLbl      = _nameCaptureLbl;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.opaque = NO;
    
        UIImage *buttonImageNormal;
        // Add the bottom bar
        UIImage *image = [UIImage imageNamed:kBtnBackgroundCapture];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.frame = CGRectMake(0, 427, 320, 53);
        [self addSubview:imageView];
        // Add the capture button
        _pictureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _pictureBtn.frame = CGRectMake(111, 433, 98, 40);
        buttonImageNormal = [UIImage imageNamed:kBtnCapture];
        [_pictureBtn setImage:buttonImageNormal forState:UIControlStateNormal];
        [_pictureBtn setImage:buttonImageNormal forState:UIControlStateDisabled];
        [_pictureBtn addTarget:self action:@selector(takePicture:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_pictureBtn];
        // Add the cancel capture
        _cancelCaptureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelCaptureBtn.frame = CGRectMake(10, 439, 54, 30);
        buttonImageNormal = [UIImage imageNamed:kBtnCancelCapture];
        [_cancelCaptureBtn setImage:buttonImageNormal forState:UIControlStateNormal];
        [_cancelCaptureBtn setImage:buttonImageNormal forState:UIControlStateDisabled];
        //[_cancelCaptureBtn setTitle:@"text" forState:UIControlStateNormal];
        [_cancelCaptureBtn addTarget:self action:@selector(cancelCapture:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_cancelCaptureBtn];
    }
    return self;
}

- (void)takePicture:(id)sender
{
    _pictureBtn.enabled = NO;
    [_delegate takePicture];
}

- (void)cancelCapture:(id)sender
{
    [_delegate cancelCapture];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
